package com.kantboot.system.user.dao.repository.entity;

import com.kantboot.system.user.domain.entity.SysPermissionRole;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysPermissionRoleRepository
extends JpaRepository<SysPermissionRole,Long>
{

    /**
     * 根据角色编码获取权限编码列表
     */
    @Query("""
    SELECT rp.permissionCode
    FROM SysPermissionRole AS rp
    WHERE rp.roleCode = :roleCode
    """)
    List<String> findPermissionCodeListByRoleCode(String roleCode);

    /**
     * 根据roleCode删除
     */
    @Transactional
    @Modifying
    @Query("""
    DELETE FROM SysPermissionRole AS rp
    WHERE rp.roleCode = :roleCode
    """)
    void deleteByRoleCode(String roleCode);


}
